package com.tobeface.wechat.message.handler;

import com.google.common.base.Objects;
import com.tobeface.wechat.message.WeChatMessage;
import com.tobeface.wechat.message.WeChatMessageChannel;
import com.tobeface.wechat.message.WeChatMessageEventTypes;
import com.tobeface.wechat.message.WeChatMessagePayloads;

/**
 * @author loudyn
 */
public abstract class MenuEventMessageHandlerSupport extends EventMessageHandlerSupport {

    @Override
    protected final boolean isEventMessageSupport(WeChatMessage message, String event) {
        if (!Objects.equal(WeChatMessageEventTypes.CLICK, event)) {
            return false;
        }

        String eventKey = (String) message.getPayloads().get(WeChatMessagePayloads.EVENTKEY_PAYLOAD);
        return isMenuEventMessageSupport(message, eventKey);
    }

    protected abstract boolean isMenuEventMessageSupport(WeChatMessage message, String eventKey);

    @Override
    protected final void onEventMessageReceived(WeChatMessageChannel channel, WeChatMessage message, String event) {
        String eventKey = (String) message.getPayloads().get(WeChatMessagePayloads.EVENTKEY_PAYLOAD);
        onMenuEventMessageReceived(channel, message, eventKey);
    }

    protected abstract void onMenuEventMessageReceived(WeChatMessageChannel channel, WeChatMessage message,
                                                       String eventKey);
}
